import 'package:flutter/material.dart';
import 'package:hkzf_flutter/widgets/common_form_item.dart';
// 表单单选组件
class CommonRadioFormItem extends StatelessWidget {
  final String? label;//  表单标签
  final List<String>? options;//  选项列表
  final int? value;//  当前选中的选项索引
  final ValueChanged<int>? onChanged;//  选项改变回调函数
  const CommonRadioFormItem({super.key, this.label, this.options, this.value, this.onChanged});

  @override
  Widget build(BuildContext context) {
    return CommonFormItem(
      label:label,
      contentBuilder: (context){
        return Container(
           child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: List.generate(options!.length, (index)=>Row(
                children: [
                  Radio(
                      value: index, //  选项绑定值
                      groupValue: value, // 激活项
                      onChanged:(i)=>{
                        onChanged!(i!)
                      },
                  ),
                  Text(options![index],style: const TextStyle(fontSize: 16.0))
                ],
              )
            ),
           ),
        );
      },
    );
  }
}